# 使用更兼容的Python基础镜像（解决Alpine兼容性问题）
FROM python:3.9-slim-bullseye

# 设置时区（按需启用）
# RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone

# 安装系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    libopenblas-dev \
    gfortran \
    && rm -rf /var/lib/apt/lists/*

# 配置pip镜像源
RUN pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple \
    && pip config set global.trusted-host mirrors.cloud.tencent.com \
    && pip install --upgrade pip

# 先单独复制依赖文件（利用Docker缓存层）
COPY requirements.txt /tmp/requirements.txt

# 安装Python依赖（包含编译依赖）
RUN pip install --no-cache-dir -r /tmp/requirements.txt

RUN python -c "import openai; print(f'OpenAI version: {openai.__version__}')"
RUN python -c "from openai import OpenAI; print('OpenAI class found')"

# 复制项目代码
COPY . /app
WORKDIR /app

# 暴露端口
EXPOSE 80

# 启动命令
CMD ["python3", "run.py", "0.0.0.0", "80"]
